/*
 * @Descripttion: 模型
 * @Author: 张正兴
 * @Date: 2021-12-27 12:30:16
 * @LastEditors: 张正兴
 */
import * as THREE from 'three'

// 流动线
const lineObj = () => {

  let map = new THREE.TextureLoader().load("/avatar2.jpg");
  // 贴图重复
  map.wrapS = THREE.RepeatWrapping;
  map.wrapT = THREE.RepeatWrapping;
  // 贴图大小
  map.repeat.set(10, 2);
  let i = 0.1;
  setInterval(function () {
    i += 0.1;
    // 贴图偏移
    map.offset = new THREE.Vector2(i, 0)
  }, 50)

  const material = new THREE.MeshBasicMaterial({
    map: map,
    side: THREE.DoubleSide
  })

  // 创建管道成型的路径(3D样条曲线)
  const path = new THREE.CatmullRomCurve3([
    new THREE.Vector3(-10, -50, -50),
    new THREE.Vector3(10, 0, 0),
    new THREE.Vector3(8, 50, 50),
    new THREE.Vector3(-5, 0, 100)
  ]);
  // path:路径   40：沿着轨迹细分数  2：管道半径   25：管道截面圆细分数
  const geometry = new THREE.TubeGeometry(path, 40, 2, 25);
  const mesh = new THREE.Mesh(geometry, material);
  return mesh
}

export {lineObj}
